<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="../../WEB-INF/c.tld" prefix="c" %>
	
<div class="main">
	<div class="container">
	
		<c:if test="${error != null}">
			<div class="alert alert-error">
				<bean:message key="${error }" />
    		</div>
		</c:if>
	
		<html:form action="${action }" method="post" onsubmit="return validateArticleForm(this);" styleClass="form-horizontal" enctype="multipart/form-data">
			<fieldset>
				<legend><bean:message key="article.Form" /></legend>
					<html:hidden property="idArticle" value="${article.idArticle }"/>
					<div class="control-group">
						<label class="control-label" for="store"><bean:message key="article.Enseigne" /></label>
						<div class="controls">
							<select name="store">
								<c:forEach items="${listEnseigne}" var="enseigne">
									<c:if test="${article.enseigne.idEnseigne == enseigne.idEnseigne}">
										<option value="${enseigne.idEnseigne}" selected="selected" >${enseigne.libelle}</option>
									</c:if>
									<c:if test="${article.enseigne.idEnseigne != enseigne.idEnseigne}">
										<option value="${enseigne.idEnseigne}" >${enseigne.libelle}</option>
									</c:if>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="refarticle"><bean:message key="article.RefArticle" /></label>
						<div class="controls">
							<html:text property="refarticle" size="16" maxlength="16" readonly="true" styleId="refarticle" value="${article.referenceArticle }"/>
							<div class="icon-refresh" id="generate"></div>
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="shortDescription"><bean:message key="article.DescriptionCourte" /></label>
							<div class="controls">
							<html:text property="shortDescription" size="16" maxlength="16" value="${article.descriptionCourte }"/>
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="modele"><bean:message key="article.Modele" /></label>
							<div class="controls">
							<html:text property="modele" size="16" maxlength="16" value="${article.modele }" />
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="quantity"><bean:message key="article.Quantite" /></label>
							<div class="controls">
							<html:text property="quantity" size="16" maxlength="16" value="${article.quantite }"/>
						</div>
					</div>					
					<div class="control-group">
							<label class="control-label" for="longDescription"><bean:message key="article.DescriptionLongue" /></label>
							<div class="controls">
							<html:text property="longDescription" size="16" maxlength="16" value="${article.descriptionLongue }" />
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="price"><bean:message key="article.Prix" /></label>
							<div class="controls">
							<html:text property="price" size="16" maxlength="16" value="${article.prix }" />
						</div>
					</div>
					<div class="control-group">
							<label class="control-label" for="picture"><bean:message key="article.image" /></label>
							<div class="controls">
							<html:file property="picture" size="16" maxlength="16" styleClass="input-file" value="${article.image }" />
							<p class="help-block">${article.image }</p>
						</div>
					</div>
					<div class="form-actions">
						<button class="btn btn-primary" type="submit"><bean:message key="general.valider" /></button>
					</div>
			</fieldset>
			<html:javascript formName="ArticleForm" />
		</html:form>
	</div>
</div>

<script type="text/javascript">

$('generate').observe('click',function(evt){
	var url = "<%= request.getContextPath() %>/generer-refarticle.do";
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var json = transport.responseText.evalJSON();
	    $('refarticle').setValue(json.ref);
	}
  });
});
</script>


